package com.glsc.ngateway.common.api.platform.dto.user;

import com.alibaba.excel.util.CollectionUtils;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;

import java.util.ArrayList;
import java.util.List;
import java.util.stream.Collectors;

/**
 * 员工领导Dto
 * 初始化全用size为0的list，防止NPE，不能用Collections.EMPTY_LIST
 * @author xuchang
 */
@AllArgsConstructor
@NoArgsConstructor
@Data
@Builder
public class UserLeadersDto {
    /**
     * 所有领导
     */
    @Builder.Default
    private List<String> allLeaders = new ArrayList<>(0);
    /**
     * 直属上级
     */
    @Builder.Default
    private List<String> directLeaders = new ArrayList<>(0);
    /**
     * 一级部门领导
     */
    @Builder.Default
    private List<String> levelOneDepLeaders = new ArrayList<>(0);

    /**
     * 去重
     */
    public UserLeadersDto distinct(){
        if(!CollectionUtils.isEmpty(this.allLeaders)){
            this.allLeaders = allLeaders.stream().distinct().collect(Collectors.toList());
        }
        if(!CollectionUtils.isEmpty(this.directLeaders)){
            this.directLeaders = directLeaders.stream().distinct().collect(Collectors.toList());
        }
        if(!CollectionUtils.isEmpty(this.levelOneDepLeaders)){
            this.levelOneDepLeaders = levelOneDepLeaders.stream().distinct().collect(Collectors.toList());
        }
        return this;
    }
}
